$(function (){

  $('.summernote').summernote({
      height: 500,
      tabsize: 2,
      lang: 'zh-CN',
      fontNames: [],
    //   toolbar: [
    //     ['insert', ['picture']],
    //   ],
    toolbar:[
        // [groupName, [list of button]]
        ['style',['bold','italic','underline','clear']],
        ['font',['strikethrough','superscript','subscript']],
        ['fontsize',['fontsize']],
        ['color',['color']],
        ['para',['ul','ol','paragraph']],
        ['height',['height']],
        ['insert',['picture',]],
        ['view',['fullscreen','codeview']],
      ],
    

    
      callbacks:{
          onImageUpload(file){

             if(file[0].size >(1024*1024*1)){

                 alert('请上传图片大小在1M以内');
                 return  false;
             }

              var _this=this;
              var xhr, formData;
              xhr = new XMLHttpRequest();
              xhr.withCredentials = false;
              xhr.open("POST", BaseUrl+"client/file/upload");
              formData = new FormData();
              formData.append("applicationIllustrationImg", file[0]);
              formData.append("uploadType",'applicationIllustrationImg');
              xhr.onload = function(e){
                      console.log(BaseUrl)
                  console.log(JSON.parse(xhr.responseText))
                  var data=JSON.parse(xhr.responseText);
                  if(data.code==200){
                      $(_this).summernote('insertImage', data.data[0].uploadFilePath,'img');
                  }else {
                      return;
                  }
              };
              xhr.send(formData);
          },

        //   onPaste: function(event) {
        //     console.log(event);
        //         if (event.clipboardData || event.originalEvent ) {
        //             var bufferText = ((event.originalEvent || event).clipboardData || window.clipboardData).getData('Text/plain');


        //             console.log("粘贴的文字" + bufferText);
        //             // if(bufferText.length > 0){
        //             //     console.log(bufferText + ">000");
        //             // }else{
        //             //     console.log(bufferText + "== 0") ;
        //                 // event.preventDefault(); // 可以删除一张图
        //             // }
        //         }
        //     }
      }
  });


})
